//
// Created by 张祎鹤严 on 2022/12/30.
//

#ifndef _DRIVER_SUPERC_H
#define _DRIVER_SUPERC_H

#include "bsp_iic.h"
#include "task_lostcounter.h"
#include "task_communicate.h"
#include "driver_chassis.h"
#define POWER_CHARGE_MAX      (100)          // 电容充电限制80w 保守了 记得改高
#define POWER_CHARGE_MAX_SC (50)
#define POWER_DISCHARGE_MAX   (300)         // 电容放电限制150w

#define SC_KP                   0.3f//(0.2f)
#define SC_KI                   (0.0005f)
#define SC_KD                   (0.f)

//send can id 312
//recv can id 311
typedef struct {        // 单位
    float V_IN;         // V
    float V_SC;         // V
    float I_IN_SC;      // A
    float I_CHASSIS;    // A
}SC_feedback_t;

typedef struct {
    uint8_t enable;
    float set_power_charge;     // 单位 W
}SC_set_t;

typedef struct {
    SC_feedback_t scFeedback;
    SC_set_t scSet;

    struct {
        float p_sc;			//电容功率(充电为正)
        float p_wheel;		//四轮电机功率
        float last_p_wheel;
    } power_fb;

} Super_Cap_t;

enum SuperCapState{    //电容充放电情况	0 电容没电	1 电容可用	2 电容满电
    FULL = 0,
    READY = 1,
    EMPTY = 2,
    Error = 3,
    Debug = 4
};

void SC_recv_message(uint8_t *data);
void super_cap_control(void);
void SC_PID_Init(void);
float SC_get_power_wheel(void);
int IF_Dead();
int IF_VOL();


extern enum SuperCapState super_cap_state;
extern Super_Cap_t superCap;


#endif //_DRIVER_SUPERC_H
